//
//  CNodeUtil.cpp
//  NinjaTurtle
//
//  Created by Nguyen Tri Chung on 1/7/15.
//
//

#include "CNodeUtil.h"

Label* CNodeUtil::createLabelTTF(const string& text, int fontSize) {
    Label* label = Label::createWithSystemFont(text, FONT_DEFAULT, fontSize);
    label->enableShadow();
    label->setHorizontalAlignment(TextHAlignment::CENTER);
    return label;
}

Label* CNodeUtil::createLabelTTF(const string& text, int fontSize, const string& fontName) {
    Label* label = Label::createWithTTF(text, fontName, fontSize);
    label->enableShadow();
    label->setHorizontalAlignment(TextHAlignment::CENTER);
    label->getTexture()->setAliasTexParameters();
    return label;
}

MenuItemSprite* CNodeUtil::createButton(const string& normalFrameName, const string& selectedFrameName) {
    Sprite* normalSprite = Sprite::createWithSpriteFrameName(normalFrameName);
    Sprite* selectedSprite = Sprite::createWithSpriteFrameName(selectedFrameName);
    normalSprite->getTexture()->setAliasTexParameters();
    selectedSprite->getTexture()->setAliasTexParameters();
    
    MenuItemSprite* button = MenuItemSprite::create(normalSprite, selectedSprite);
    
    return button;
}

MenuItemSprite* CNodeUtil::createButtonFontSmall(const string& text, int fontSize, string normalFrameName, string selectedFrameName) {
    Sprite* normalSprite = Sprite::createWithSpriteFrameName(normalFrameName);
    Sprite* selectedSprite = Sprite::createWithSpriteFrameName(selectedFrameName);
    normalSprite->getTexture()->setAliasTexParameters();
    selectedSprite->getTexture()->setAliasTexParameters();
    
    MenuItemSprite* button = MenuItemSprite::create(normalSprite, selectedSprite);
    
    Label* normalText = CNodeUtil::createLabelTTF(text, fontSize, FONT_ARCADE);
    normalText->setPosition(Point(button->getContentSize().width / 2, button->getContentSize().height / 2));
    normalText->enableShadow();
    normalSprite->addChild(normalText);
    Label* selectedText = CNodeUtil::createLabelTTF(text, fontSize, FONT_ARCADE);
    selectedText->setPosition(Point(button->getContentSize().width / 2, button->getContentSize().height / 2));
    selectedText->enableShadow();
    selectedSprite->addChild(selectedText);
    
    return button;
}